package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 添加用户的评论信息表
 */
@Getter
@Setter
public class StrategyComment {
    //添加状态
    public static final int STATE_DEFAULT = 0;//正常状态
    public static final int STATE_COMMEND = 1;//推荐状态
    public static final int STATE_DORBIDDEN = 2;//禁用状态

    private Long id;//主键

    private User user;//用户
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;//创建评论时间

    private String content;//评论内容

    private String imgUrls;//评论图片

    private Integer starNum;//点评数

    private Strategy strategy;//绑定攻略

    private String nickName; //随便加的昵称

    private Integer state = STATE_COMMEND;//状态
    @DateTimeFormat(pattern = "yyyy-MM-dd ")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date commendTime;//推荐时间
    //添加
    private Tag tag;
    private String[] imgUrlss;

    public String getStateDisplay() {
        if (state == StrategyComment.STATE_DEFAULT) {
            return "正常";
        } else if (state == StrategyComment.STATE_COMMEND) {
            return "推荐";
        } else if (state == StrategyComment.STATE_DORBIDDEN) {
            return "禁用";
        } else {
            return "";
        }
    }

    public String getJsonString() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("state", state);
        return JSONUtils.toJSONString(map);
    }
}